package com.vcredit.creditcat.service;
import com.vcredit.creditcat.model.PrivilegeCat;
import com.vcredit.creditcat.persistence.base.PrivilegeCatMapper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
/**
 * 
 **/
@Service
public class PrivilegeCatService {
	@Autowired
    private PrivilegeCatMapper mapper;
    
	@CacheEvict(key = "'PrivilegeCat'", value = "default")
    public void insert(PrivilegeCat obj){
    	mapper.insert(obj);
    }
    
    @CacheEvict(key = "'PrivilegeCat'", value = "default")
    public void update(PrivilegeCat obj){
    	mapper.update(obj);
    }
    
    public List<PrivilegeCat> findAll(){
		return mapper.findAll();
	}
    
    @Cacheable(key = "'PrivilegeCat'", value = "default")
    public Map<Integer,PrivilegeCat> findAllForMap(){
    	Map<Integer,PrivilegeCat> result = new HashMap<Integer,PrivilegeCat>();
    	List<PrivilegeCat> findAll = this.findAll();
    	for (PrivilegeCat privilegeCat : findAll) {
    		result.put(privilegeCat.getId(), privilegeCat);
		}
    	return result;
	}
	
	private List<PrivilegeCat> find(PrivilegeCat obj){
		return mapper.find(obj);
	}
}